<%--

    SettingsPage.jsf
    Страница для работы с настройками приложения 

--%>

<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8" %>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Goodwill - Настройки</title>
    <link rel="stylesheet" href="resources/css/main.css"/>
    <link rel="stylesheet" href="resources/css/stylesheet.css"/>
    <link rel="stylesheet" href="resources/css/simple_tables.css"/>
    <script type="text/javascript" src="resources/js/prototype.js"></script>
    <script type="text/javascript" src="resources/js/hltable.js"></script>
    <style type="text/css">
        .s_norm
        {
            font-size:100%;
        }

        .s_system
        {
            color:dimgray;
            font-size:80%;
        }

        .hooverRow
        {
            background-color: yellow;
        }
    </style>
    <script type="text/javascript">
        function setSettingValue(sname)
        {
            var svalue = prompt("Введите новое значение опции:");
            if (svalue) _setSettingValue(sname, svalue);
        }
    </script>

</head>
<body>
<f:view>
    <jsp:include page="menu.jsp"/>
    <jsp:include page="status.jsp"/>

    <a4j:form prependId="false" id="jsForm">
        <a4j:jsFunction name="_setSettingValue" action="#{SettingsBean.saveSetting}" reRender="tableSettings">
            <a4j:actionparam name="key" assignTo="#{SettingsBean.key}"/>
            <a4j:actionparam name="val" assignTo="#{SettingsBean.value}"/>
        </a4j:jsFunction>
    </a4j:form>

    <h:dataTable value="#{SettingsBean.settings}" var="setting" id="tableSettings" cellpadding="0" cellspacing="0" styleClass="tbl3" rules="all">
        <f:facet name="header">
            <h:outputText value="Настройки системы"/>
        </f:facet>

        <rich:column>
            <h:outputLink value="#" onclick="setSettingValue('#{setting.key}');" title="Редактировать">
                <h:graphicImage value="resources/img/edit.gif"/>
            </h:outputLink>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Наименование"/>
            </f:facet>

            <h:outputText value="#{setting.comment}" rendered="#{!setting.isHidden}" styleClass="s_norm"/>
            <h:outputText value="#{setting.comment}" rendered="#{setting.isHidden}" styleClass="s_system"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Значение"/>
            </f:facet>

            <h:outputText value="#{setting.value}" rendered="#{!setting.isHidden}" styleClass="s_norm"/>
            <h:outputText value="#{setting.value}" rendered="#{setting.isHidden}" styleClass="s_system"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Системное наименование"/>
            </f:facet>
            <h:outputText value="#{setting.key}" rendered="#{!setting.isHidden}" styleClass="s_norm"/>
            <h:outputText value="#{setting.key}" rendered="#{setting.isHidden}" styleClass="s_system"/>
        </rich:column>

    </h:dataTable>
</f:view>
<script type="text/javascript">
    highlightTableRows("tableSettings", "hooverRow");
</script>
</body>
</html>
